package java8.timeutil;

import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.List;

/**
 * @author Cheng Jun
 * @version 1.0
 * Description:
 * @date 2019/8/11 20:46
 */
public class PeriodStudy {

    public static void main(String[] args) {

        //
        Period firstLovePeriod = Period.of(5, 10, 10);

        LocalDate today = LocalDate.now();
        System.out.println(today.toString().substring(5, 10));

        //根据文本创建LocalDate对象(JAVA诞生日):1995-05-23
        LocalDate birthday = LocalDate.parse("1995-05-23");

        //P24Y2M22D
        Period age = Period.between(birthday, today);
        int years = age.getYears();
        int months = age.getMonths();
        int days = age.getDays();

        Period age1 = birthday.until(today);

        //8849
        long accumulatedDays = birthday.until(today, ChronoUnit.DAYS);
        //290
        long accumulatedMonths = birthday.until(today, ChronoUnit.MONTHS);
        //24
        long accumulatedYears = birthday.until(today, ChronoUnit.YEARS);

        List<TemporalUnit> temporalUnitList = age.getUnits();

        System.out.println("age1:" + age1);
        System.out.println(years);
        System.out.println(months);
        System.out.println(days);

        System.out.println(accumulatedDays);
        System.out.println(accumulatedMonths);
        System.out.println(accumulatedYears);

        String test = "";
        System.out.println(test.contains(""));
        test = test + "11" + ",";
        System.out.println(test.contains(""));
    }
}
